//*****************************************************************
/*
  NUSIC (Network Uncompressed Sound Intercommunicate Console): A Graphical User Interface for Jacktrip, a system for
  High-Quality Audio Network Performance over the Internet.

  http://code.google.com/p/nusic
  http://code.google.com/p/jacktrip

  Copyright (c) 2009 Elie El Noune
  Electrical and Computer Engineering
  American University of Beirut

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*/
//*****************************************************************

#ifndef WINDOW_H
#define WINDOW_H

#include <QWidget>
#include <QProcess>
#include "Jacktrip.h"

QT_BEGIN_NAMESPACE
class QGroupBox;
class QRadioButton;
class QComboBox;
class QCheckBox;
class QTextEdit;
class QPushButton;
class QLineEdit;
class QProcess;
class QGridLayout;
class QFormLayout;
QT_END_NAMESPACE


class Window : public QWidget
{
    Q_OBJECT

public:
    Window(QWidget *parent = 0);
    ~Window(){
           Settings->close();
        delete Settings;
        mJacktrip->kill();
    }
 // Required
    void CreateServer();
    void CreateClient();
    void CreateHostName();
    // basic options
    void CreateLoopback();
    void CreateSamplingRate(); //rtaudio
    void CreateBufferSize();   //rtaudio
    void CreateBitRes();
    void CreateQueueLength();
    void CreateNumberChannels();

    void StartButton();
    void StopButton();
    void CreatePortOffset();
    void CreateAdvanced();

    void CreateMessageView();
    void DisplayCommand();
    QString GetTime();
    //to do in another dialog: advanced options

    void CreateJamlink();
    void CreateJack();
    void CreateRtaudio();
    void CreateZeroUnderrun();
    void CreateBindPort();
    void CreatePeerPort();
    void CreateRedundancy();
    void CreateClientName();

    //Groups functions
    QGroupBox * CreateModeGroup();
    QGroupBox * CreateASIOOptionsGroup();
    QGroupBox * CreateMoreOptionsGroup();
    QGroupBox * CreateStreamGroup();
    QGroupBox * CreateAdvancedOptionsGroup();
    QGroupBox * CreateMessageBox();

    //advanced group functions
    QGroupBox * CreateInterfaceGroup();
    QGroupBox * CreatePortGroup();
    QGroupBox * CreateOtherGroup();
    QGroupBox * CreateClientGroup();

    public slots:

    void readStdout();
    void setMode();
    void setHost();
    void setLoopback();
    void setNumberChannels();
    void setQueueLength();
    void setBitRes();
    void setSampleRate();
    void setBufferSize();
    void setPortOffset();
    
    void StartJacktrip();
    void StopJacktrip();
    
    void setJamlink();
    void setRtaudio();
    void setBindPort();
    void setPeerPort();
    void setRedundancy();
    void setUnderrunMode();
    void setClientName();

    void showSettings() {
//    Settings->resize(300, 200);
    Settings->setWindowTitle(tr("Settings"));
    Settings->show();
    }

private:

    QString command;
//Mode Group
    QRadioButton *ServerButton;
    QRadioButton *ClientButton;
    QLineEdit *HostNameList;
//ASIO Options Group
    QComboBox *SamplingRateList;
    QComboBox *BufferSizeList;
    QComboBox *BitResList;
//Other Options Group
    QCheckBox *LoopbackBox;
    QLineEdit *NumberChannelsLine;
    QLineEdit *QueueLengthLine;
//Stream Group
    QPushButton *Start;
    QPushButton *Stop;
//Advanced Options Group
    QLineEdit *PortOffsetLine;
    QPushButton *Advanced;

//in the dialog


    //Interface Group
    QCheckBox *JamlinkBox;
    QCheckBox *JackBox;
    QCheckBox *RtaudioBox;

    //UDP ports Group
    QLineEdit *PeerPortLine;
    QLineEdit *BindPortLine;

    //Stream Group
    QComboBox *RedundancyList;
    QComboBox *UnderrunList;
    QLineEdit *ClientNameLine;

   // QWidget *Settings;
     QDialog *Settings;
    QFormLayout *Form;
    Jacktrip *mJacktrip;

    QTextEdit *Messages;
    QGroupBox *ASIOOptions;
    void SetJacktrip();
};


#endif
